package it.polimi.swim.entity;

import java.io.Serializable;


import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.JoinColumn;

@NamedQueries({
	@NamedQuery(name = "SystemUser.getAll", query = "SELECT h FROM SystemUser h"),
	@NamedQuery(name = "SystemUser.getUserCompletedHelp", query = "SELECT h FROM SystemUser u, HelpRequest h WHERE u.id = :id AND u.id = h.creator AND h.status = 1"),
	@NamedQuery(name = "SystemUser.getUserByName", query = "SELECT u FROM SystemUser u WHERE u.name = :name AND u.surname = :surname"),
	@NamedQuery(name = "SystemUser.getUserById", query = "SELECT u FROM SystemUser u WHERE u.id = :id"),
	@NamedQuery(name = "SystemUser.validateLogin", query = "SELECT u FROM SystemUser u WHERE u.mail = :mail AND u.psw = :psw"), 
	@NamedQuery(name = "SystemUser.duplicateUser", query = "SELECT u FROM SystemUser u WHERE u.mail = :mail") })
@Entity
@Table(name = "System_User")
public class SystemUser implements Serializable {

	private static final long serialVersionUID = 2426325952739991058L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private int id;

	@Column(name = "mail", nullable = false)
	private String mail;

	@Column(name = "psw", nullable = false)
	private String psw;

	@Column(name = "type", nullable = false)
	private String type;

	@Column(name = "name", nullable = false)
	private String name;

	@Column(name = "surname", nullable = false)
	private String surname;

	@Column(name = "date")
	private Date date;

	@Column(name = "city", nullable = false)
	private String city;

	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name = "skillUser", joinColumns = @JoinColumn(name = "idSystemUser", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "idSkill", referencedColumnName = "id"))
	private List<Skill> skillUser;

	public List<Skill> getSkill() {
		return skillUser;
	}
	
	public void setSkill(List<Skill> s){
		skillUser=s;
	}


	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name = "userFriendRequest", joinColumns = @JoinColumn(name = "idSystemUser", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "idFriendRequest", referencedColumnName = "id"))
	private Set<Friend> userFriendRequest;

	public Set<Friend> getFriendRequest() {
		return userFriendRequest;
	}
/*@OneToMany(mappedBy = "user")
	private Set<Feedback> feedback;

	public Set getFeedback() {
		return feedback;
	}*/
	
	@OneToMany(mappedBy = "creator", fetch=FetchType.EAGER)
	private Set<HelpRequest> creator;
	
	@OneToMany(mappedBy = "receiver", fetch=FetchType.EAGER)
	private Set<HelpRequest> receiver;

	/*public Set getcreatedHelp() {
		return feedback;
	}*/

	// Set and Get

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getPsw() {
		return psw;
	}

	public void setPsw(String psw) {
		this.psw = psw;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Set<HelpRequest> getCreator() {
		return creator;
	}

	public void setCreator(Set<HelpRequest> creator) {
		this.creator = creator;
	}

	public Set<HelpRequest> getOtherHelp() {
		return receiver;
	}

	public void setReceiver(Set<HelpRequest> receiver) {
		this.receiver = receiver;
	}

}
